﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ES.Shared.Data
{
    [Serializable]
    public class RelationInfo
    {
        public RelationInfo()
        {
            _columnMappings = new RelationColumnInfoCollection();
        }

        public RelationInfo(string primaryKeyTableName, TableSchemaType primaryKeyTableSchemaType, RelationColumnInfo[] columnMappings)
            : this()
        {
            PrimaryKeyTableName = primaryKeyTableName;
            PrimaryKeyTableSchemaType = primaryKeyTableSchemaType;
            UpdateAction = RelationActionType.Cascade;
            DeleteAction = RelationActionType.Cascade;
            CheckExisting = true;
            _columnMappings.AddRange(columnMappings);
        }

        public RelationInfo(string primaryKeyTableName, TableSchemaType primaryKeyTableSchemaType, RelationColumnInfo[] columnMappings, RelationActionType updateAction, RelationActionType deleteAction, bool checkExisting)
            : this()
        {
            PrimaryKeyTableName = primaryKeyTableName;
            PrimaryKeyTableSchemaType = primaryKeyTableSchemaType;
            UpdateAction = updateAction;
            DeleteAction = deleteAction;
            CheckExisting = checkExisting;
            _columnMappings.AddRange(columnMappings);
        }

        public string PrimaryKeyTableName
        { get; set; }

        public TableSchemaType PrimaryKeyTableSchemaType
        { get; set; }

        public RelationActionType UpdateAction
        { get; set; }

        public RelationActionType DeleteAction
        { get; set; }

        public bool CheckExisting
        { get; set; }

        private RelationColumnInfoCollection _columnMappings;

        public RelationColumnInfoCollection ColumnMappings
        {
            get { return _columnMappings; }
        }
    }
}
